<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p{
            margin: 0;
        }
        img{
            display: block;
        }
    </style>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react@17.js"></script>
<script src="../react-dom@17.js"></script>
<script src="../babel.js"></script>
<script type="text/babel">
    class App extends React.Component{
        state = {
            html:"<h1>好好学习天天向上</h1>",
            content:""
        }
        render(){ 
            let {html,content} = this.state;
            return (
                <div>
                    {
                        /*  渲染html 富文本标签 */
                    }
                    <div dangerouslySetInnerHTML={{__html:html}}></div>
                    <button onClick={()=>{
                        this.setState({
                            html:"<img src='' />"
                        })
                    }}>改变</button>
                    <button onClick={()=>this.getInfo()}>获取商品详情</button>
                    <div dangerouslySetInnerHTML={{__html:content}}></div>
                </div>
            )
        }
        getInfo(){
            let xhr = new XMLHttpRequest();
            xhr.open("get",'https://apif.java.crmeb.net/api/front/product/detail/634?type=normal');
            xhr.send();
            xhr.onreadystatechange = ()=>{
                if(xhr.readyState === 4){
                    console.log(JSON.parse(xhr.response))
                    let res = JSON.parse(xhr.response);
                    let content = res.data.productInfo.content;
                    console.log(content)
                    this.setState({
                        content
                    })
                }
            }
        }
    }
    ReactDOM.render(<App/>,document.getElementById("root"))
</script>
</html>